package com.gl.ruanzhu.service.impl;

import com.gl.basis.common.pojo.Page;
import com.gl.basis.common.util.ConverBeanUtils;
import com.gl.ruanzhu.indto.TaskInDto;
import com.gl.ruanzhu.model.*;
import com.gl.ruanzhu.outDto.*;
import com.gl.ruanzhu.service.IScienceServicesDalService;
import com.gl.ruanzhu.service.IScienceServicesService;
import ma.glasnost.orika.MapperFactory;
import ma.glasnost.orika.impl.DefaultMapperFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ScienceServicesServiceImpl implements IScienceServicesService {

    @Autowired
    private IScienceServicesDalService scienceServicesDalService;


    @Override
    public Page<TaskOutDto> getAll(Page<TaskInDto> page) {
        List<Task> list = scienceServicesDalService.getALL(page.getParams());
        MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
        List<TaskOutDto> taskOutDTOList = mapperFactory.getMapperFacade().mapAsList(list, TaskOutDto.class);
        //        com.github.pagehelper.Page<Task> pager = (com.github.pagehelper.Page<Task>) list;
        Page<TaskOutDto> newPage=new Page<>();
        Long totasize = (long)taskOutDTOList.size();
        newPage.setOrder(page.getOrder());
        newPage.setIsPage(page.getIsPage());
        newPage.setParams(page.getParams());
        newPage.setPageNo(page.getPageNo());
        newPage.setPageSize(page.getPageSize());
        newPage.setTotalSize(totasize);
        newPage.setMsg("查询成功");
        newPage.setResult(taskOutDTOList);
        return newPage;
    }


    @Override
    public List<TaskOutDto> showDesignSon(Map<String, Object> params) {
        List<Task> list = scienceServicesDalService.showDesignSon(params);
        MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
        List<TaskOutDto> TaskOutDTOList = mapperFactory.getMapperFacade().mapAsList(list, TaskOutDto.class);
        return TaskOutDTOList;
    }

    @Override
    public TaskOutDto getDetails(Map<String, Object> params) {
        return  ConverBeanUtils.doToDto(scienceServicesDalService.getDetails(params),TaskOutDto.class);
    }

    @Override
    public List<TaskSupplierOutDTO> getSuppliers(Map<String, Object> params) {
        List<TaskSupplier> list = scienceServicesDalService.getSuppliers(params);
        MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
        List<TaskSupplierOutDTO> dtoList = mapperFactory.getMapperFacade().mapAsList(list, TaskSupplierOutDTO.class);
        return dtoList;
    }

    @Override
    public List<ContractOutDTO> getContract(Map<String, Object> params) {
        List<Contract> list = scienceServicesDalService.getContract(params);
        MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
        List<ContractOutDTO> dtoList = mapperFactory.getMapperFacade().mapAsList(list, ContractOutDTO.class);
        return dtoList;
    }

    @Override
    public Page<TaskOutDto> getUnResponded(Page<TaskInDto> page) {
        List<TaskOutDto> list = scienceServicesDalService.getUnResponded(page.getParams());
        //com.github.pagehelper.Page<TaskOutDTO> pager = (com.github.pagehelper.Page<TaskOutDTO>) list;
        Page<TaskOutDto> newPage=new Page<>();
        newPage.setOrder(page.getOrder());
        newPage.setIsPage(page.getIsPage());
        newPage.setParams(page.getParams());
        newPage.setPageNo(page.getPageNo());
        newPage.setPageSize(page.getPageSize());
        Long totasize = (long)list.size();
        newPage.setTotalSize(totasize);
        newPage.setMsg("查询成功");
        newPage.setResult(list);
        return newPage;
    }

    @Override
    public List<TaskPlanOutDTO> getPlanState(Map<String, Object> params) {
        List<TaskPlan> list = scienceServicesDalService.getPlanState(params);
        MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
        List<TaskPlanOutDTO> dtoList = mapperFactory.getMapperFacade().mapAsList(list, TaskPlanOutDTO.class);
        return dtoList;
    }

    @Override
    public List<TaskPersonOutDTO> getPerson(Map<String, Object> params) {
        List<TaskPerson> list = scienceServicesDalService.getPerson(params);
        MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
        List<TaskPersonOutDTO> dtoList = mapperFactory.getMapperFacade().mapAsList(list, TaskPersonOutDTO.class);
        return dtoList;
    }

    @Override
    public List<TaskDesignOutDto> getDesign(Map<String, Object> params) {
        List<TaskDesign> list = scienceServicesDalService.getDesign(params);
        MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
        List<TaskDesignOutDto> dtoList = mapperFactory.getMapperFacade().mapAsList(list, TaskDesignOutDto.class);
        return dtoList;
    }

    @Override
    public List<CirculationListOutDTO> getCirculationList(Map<String, Object> params) {
        List<CirculationList> list = scienceServicesDalService.getCirculationList(params);
        MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
        List<CirculationListOutDTO> dtoList = mapperFactory.getMapperFacade().mapAsList(list, CirculationListOutDTO.class);
        return dtoList;
    }

    @Override
    public Times getTimes(Map<String, Object> params) {
        return scienceServicesDalService.getTimes(params);
    }
}
